package com.suyl.callback.highConcurrency.service.impl;

import com.suyl.callback.highConcurrency.service.CallBack;

/**
 * 回调实现类A
 */
public class A implements CallBack {

    private B b;

    public A(B b) {
        this.b = b;
    }

    /**
     * 回调入口
     *
     * @param question
     */
    public void ask(final String question) {
        System.out.println("A问了B一个问题");
        // 启动个异步线程
        new Thread(() -> {
            b.excuteMessage(A.this, question);
        }).start();
        // 同步执行
        pay();
    }

    public void pay() {
        System.out.println("我已经执行完了");
    }

    // 异步调用方法
    @Override
    public String solve(String result) {
        System.out.println("success");
        System.out.println("B告诉A答案是：" + result);
        return result;
    }
}
